package com.xiaoyg.concurrent;

import lombok.var;
import org.springframework.scheduling.concurrent.CustomizableThreadFactory;

import java.util.concurrent.*;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.atomic.LongAdder;

public class AtomicLongDemo {


    public static void main(String[] args) {
        long now = System.currentTimeMillis();
        ExecutorService fixedThreadPool = Executors.newFixedThreadPool(4);

        AtomicInteger atomicInteger = new AtomicInteger();

        var counter = new LongAdder();

        for (int i = 0; i < 1000; i++) {
            fixedThreadPool.execute(counter::increment);
        }

        try {
            Thread.sleep(1000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        long end = System.currentTimeMillis();
        System.out.println(counter.sum() + "               "+(end-now));
    }

}
